
var displayStart = 1;
var endPage = null;
var layer = layui.layer;
var form = null;
var list = null;
var table=layui.table;
var viewUrl=""
window.onload=function (e) {
    if(sessionStorage.getItem('loginName')==null){
        layer.msg("检测到您未登录，请先登录....")
        setTimeout(function() {
            location.href = '/toHRPage';
        }, 1);
    }
}

layui.use(['form', 'element'], function() {
    form = layui.form;
    //在线填报查询
    searchFilling(1)
    form.on('submit(searchFilling)', function() {
        searchFilling(1);
        return false;
    });
    $('.fristPage').click(function() {
        searchFilling(1);
        return false;
    });
    $('.lastPage').click(function() {
        searchFilling((displayStart > 1 ? displayStart - 1 : 1));
        return false;
    });
    $('.nextPage').click(function() {
        searchFilling((displayStart < endPage ? displayStart + 1 : endPage));
        return false;
    });
    $('.endPage').click(function() {
        searchFilling(endPage);
        return false;
    })
    //简历直投查询
    searchSend(1)
    form.on('submit(searchSend)', function() {
        searchSend(1);
        return false;
    });
    $('.fristPageOfSend').click(function() {
        searchSend(1);
        return false;
    });
    $('.lastPageOfSend').click(function() {
        searchSend((displayStart > 1 ? displayStart - 1 : 1));
        return false;
    });
    $('.nextPageOfSend').click(function() {
        searchSend((displayStart < endPage ? displayStart + 1 : endPage));
        return false;
    });
    $('.endPageOfSend').click(function() {
        searchSend(endPage);
        return false;
    })

})

//查看详情方法
function fillingInfo(index) {
    $("#infoDiv").empty();
    var trs='';
    $.ajax({
        url: '' +'/apply-info/viewInfo',
        method: 'POST',
        contentType: 'application/json',
        data: JSON.stringify({
            id:index
        }),
        success: function (res) {
            //获取弹出层数据
            if(res.code==200){
                trs+='<div class="layui-collapse">' +
                    '<div class="layui-colla-item" style="margin: 15px">' +
                    '<h2 class="layui-colla-title">'
                var str=res.data.applyUserName+"-信息详情"
                trs+=str
                //获取layui-colla-content的内容
                trs+='  </h2> '
                trs+='  <div class="layui-colla-content layui-show"> '
                trs+='<div style="margin: 5px;" align="center"><h3><b style="color:#1E9FFF;">------------基础信息------------</b></h3></div>'
                trs += '<ul class=" ">';
                // trs += '<label class="label_name" style="line-height: 2"><b style="color: #f5222d">——上报记录'+j+':             </b></label>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  姓名:             </b><span style="color: #1890ff">'+res.data.applyUserName+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  性别:             </b><span style="color: #1890ff">'+res.data.sex+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  意向岗位:          </b><span style="color: #1890ff">'+res.data.intentionPost+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  联系电话:          </b><span style="color: #1890ff">'+res.data.telephone+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  生日:             </b><span style="color: #1890ff">'+res.data.birthday+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  身高:             </b><span style="color: #1890ff">'+res.data.height+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  政治面貌:          </b><span style="color: #1890ff">'+res.data.tpolitical+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  毕业院校:          </b><span style="color: #1890ff">'+res.data.graduationSchool+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  毕业时间:          </b><span style="color: #1890ff">'+res.data.graduationDay+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  学历:             </b><span style="color: #1890ff">'+res.data.education+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  专业:             </b><span style="color: #1890ff">'+res.data.major+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  籍贯:                    </b><span style="color: #1890ff">'+res.data.nativePlace+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  特长:                    </b><span style="color: #1890ff">'+res.data.speciality+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  爱好:                    </b><span style="color: #1890ff">'+res.data.hobby+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  意向工作城市:             </b><span style="color: #1890ff">'+res.data.intendedCity+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  英语水平:                    </b><span style="color: #1890ff">'+res.data.englishLevel+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  英语证书:                    </b><span style="color: #1890ff">'+res.data.englishCertificate+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  擅长办公软件:                 </b><span style="color: #1890ff">'+res.data.officeSoftware+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  消息来源:                    </b><span style="color: #1890ff">'+res.data.source+'</span></label></li>';
                trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  投递时间:                    </b><span style="color: #1890ff">'+res.data.createTime.replace('T',' ')+'</span></label></li>';
                trs += '</ul>';
                trs+='<div style="margin: 5px;" align="center"><h3><b style="color:#1E9FFF;">------------个人履历------------</b></h3></div>'
                trs+='<div style="margin: 10px;" align="center"><h4><b style="color:red;">● 实习经历 </b></h4></div>'
                if(res.data.internshipInfoVos.length==0){
                    trs+='<span style="color:#1890ff;">无实习经历</span>'
                }else {
                    for (var i = 0; i <res.data.internshipInfoVos.length; i++) {
                        var x=i+1;
                        trs+='<span style="color:#1890ff;margin: 10px">——实习经历 '+x+'</span>'
                        trs += '<ul class=" ">';
                        // trs += '<label class="label_name" style="line-height: 2"><b style="color: #f5222d">——上报记录'+j+':             </b></label>';
                        trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  开始时间:             </b><span style="color: #1890ff">'+res.data.internshipInfoVos[i].startTime+'</span></label></li>';
                        trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  结束时间:             </b><span style="color: #1890ff">'+res.data.internshipInfoVos[i].endTime+'</span></label></li>';
                        trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  公司名称:          </b><span style="color: #1890ff">'+res.data.internshipInfoVos[i].companyName+'</span></label></li>';
                        trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  岗位:          </b><span style="color: #1890ff">'+res.data.internshipInfoVos[i].postName+'</span></label></li>';
                        trs += '</ul>';
                    }
                }
                trs+='<div style="margin: 10px;" align="center"><h4><b style="color:red;">● 培训经历 </b></h4></div>'
                if(res.data.trainInfoVos.length==0){
                    trs+='<span style="color:#1890ff;">无培训经历</span>'
                }else {
                    for (var j = 0; j < res.data.trainInfoVos.length; j++) {
                        var y=j+1;
                        trs+='<span style="color:#1890ff;margin: 10px">——培训经历 '+y+'</span>'
                        trs += '<ul class=" ">';
                        // trs += '<label class="label_name" style="line-height: 2"><b style="color: #f5222d">——上报记录'+j+':             </b></label>';
                        trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  培训时间:             </b><span style="color: #1890ff">'+res.data.trainInfoVos[j].trainTime+'</span></label></li>';
                        trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  培训内容:             </b><span style="color: #1890ff">'+res.data.trainInfoVos[j].trainInfo+'</span></label></li>';
                        trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  是否获得证书:          </b><span style="color: #1890ff">'+res.data.trainInfoVos[j].obtainCertificate+'</span></label></li>';
                        trs += '</ul>';
                    }
                }
                trs+='<div style="margin: 10px;" align="center"><h4><b style="color:red;">● 家庭成员 </b></h4></div>'
                if(res.data.familyInfoVos.length==0){
                    trs+='<span style="color:#1890ff;">未填写家庭成员</span>'
                }else {
                    for (var k = 0; k < res.data.familyInfoVos.length; k++) {
                        var z=k+1;
                        trs+='<span style="color:#1890ff;margin: 10px">——家庭成员 '+z+'</span>'
                        trs += '<ul class=" ">';
                        // trs += '<label class="label_name" style="line-height: 2"><b style="color: #f5222d">——上报记录'+j+':             </b></label>';
                        trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  称谓:             </b><span style="color: #1890ff">'+res.data.familyInfoVos[k].appellation+'</span></label></li>';
                        trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  姓名:             </b><span style="color: #1890ff">'+res.data.familyInfoVos[k].name+'</span></label></li>';
                        trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  现居地:          </b><span style="color: #1890ff">'+res.data.familyInfoVos[k].nowLive+'</span></label></li>';
                        trs += '<li style="line-height:1.5"><label class="label_name" style="width: auto;"><b style="color:red;">●  工作单位:          </b><span style="color: #1890ff">'+res.data.familyInfoVos[k].nowWorkplace+'</span></label></li>';
                        trs += '</ul>';
                    }
                }
                trs+='</div></div></div>';
                //trs+='<div align="center" style="margin: 10px"><button class="layui-btn layui-btn-danger" onclick=""><b><i class="layui-icon">&#xe605;</i></b></button></div>';
            }
            //加载折叠面板
            $("#infoDiv").append(trs);
            layui.element.init()
            layer.open({
                type: 1,
                title: '信息详情',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area : ['100%' , '80%'],
                content: $('#infoDiv'),
                end:function () {
                    $('#infoDiv').css('display','none')
                }
            });
        }
    })
}
//预览简历方法
function viewResume(index) {
    window.open(viewUrl+index);
}

function searchFilling(index) {
    //加载层遮罩
    var loading = layer.load(3, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });
    if (!index) var index = displayStart;
    var data = form.val('fillingData');
    data.displayStart = index;
    $.ajax({
        url: '' + '/apply-info/listApplyInfo',
        method: 'POST',
        contentType: 'application/json',
        data: JSON.stringify(data),
        success: function(res) {
            //关闭加载层
            layer.close(loading)
            //total=Math.ceil(res.data.records.length/10);
            $('#fillingTable').empty();
            displayStart = res.data.current;
            endPage = res.data.pages;
            list = res.data.records;
            for (var i = 0; i < res.data.records.length; i++) {
                $('#fillingTable').append(
                    "<tr><td>" + res.data.records[i].applyUserName + "</td>" +
                    "<td>" + res.data.records[i].telephone + "</td>" +
                    "<td>" + res.data.records[i].intentionPost + "</td>" +
                    "<td class='operation'><button type='button' class='layui-btn layui-btn-sm layui-btn-normal ' onclick='fillingInfo(" + res.data.records[i].id + ")'>详情</button></td>" +
                    "</tr>"
                );
            }
            if(res.data.records.length==0){
                $('#total').html(0)
            }else
                $('#total').html(Math.ceil(res.data.records[0].allTotal/Number($('#displayLength').val())))
            $('#page').html(displayStart)
        }
    })
}

function searchSend(index) {
    //加载层遮罩
    var loading = layer.load(3, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });
    if (!index) var index = displayStart;
    var data = form.val('sendData');
    data.displayStart = index;
    data.displayLength = $('#displayLength').val();
    $.ajax({
        url: '' + '/resume-info/listResume',
        method: 'POST',
        contentType: 'application/json',
        data: JSON.stringify(data),
        success: function(res) {
            //关闭加载层
            layer.close(loading)
            //total=Math.ceil(res.data.records.length/10);
            $('#sendTable').empty();
            displayStart = res.data.current;
            endPage = res.data.pages;
            list = res.data.records;
            for (var i = 0; i < res.data.records.length; i++) {
                $('#sendTable').append(
                    "<tr><td>" + res.data.records[i].applyUserName + "</td>" +
                    "<td>" + res.data.records[i].userTel + "</td>" +
                    "<td>" + res.data.records[i].intentionPost + "</td>" +
                    "<td class='operation'><button type='button' class='layui-btn layui-btn-sm layui-btn-normal ' onclick='viewResume(\"" + res.data.records[i].resumePath + "\")'>预览简历</button></td>" +
                    "</tr>"
                );
            }
            if(res.data.records.length==0){
                $('#totalOfSend').html(0)
            }else{
                $('#totalOfSend').html(Math.ceil(res.data.records[0].allTotal/Number($('#displayLength').val())))
                viewUrl=res.data.records[0].nginxIp
            }
            $('#pageOfSend').html(displayStart)

        }
    })
}
